import Vue from 'vue'
import Router from 'vue-router'
import Routes from './router'

Vue.use(Router)

const router = new Router({
    base: process.env.BASE_URL,
    routes: Routes,
    mode:'history'
})

const originalPush = Router.prototype.push

//使用路由时重写push对错误进行捕获
Router.prototype.push = function push(location){
    return originalPush.call(this, location).catch(err => err)
}

const originalReplace = Router.prototype.replace

//使用路由时重写replace对错误进行捕获
Router.prototype.replace = function replace(location){
    return originalReplace.call(this, location).catch(err => err)
}

export default router